package opreation;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:此类添加书籍操作，改进：扩容，判断是否满。
 * Author:  LiuTao
 * Version: 1.0
 * Date:    2024-01-03  09:06
 */
public class AddOpreation implements IOpreation{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入书名");
        String name = scanner.nextLine();
        System.out.println("请输入作者");
        String author = scanner.nextLine();
        System.out.println("请输入类型");
        String type = scanner.nextLine();
        System.out.println("请输入价格");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);
        int currentSize = bookList.getUsedSize();
        if(currentSize == bookList.getLength()) {
            bookList.addBook(book);
        }
        bookList.setBooks(currentSize,book);
        bookList.setUsedSize(currentSize+1);
    }
}
